/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Equipment")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Equipment.findAll", query = "SELECT e FROM Equipment e ORDER BY e.equipName ASC"),
    @NamedQuery(name = "Equipment.findByEquipID", query = "SELECT e FROM Equipment e WHERE e.equipID = :equipID"),
    @NamedQuery(name = "Equipment.findByEquipName", query = "SELECT e FROM Equipment e WHERE e.equipName = :equipName"),
    @NamedQuery(name = "Equipment.findByEquipModelNum", query = "SELECT e FROM Equipment e WHERE e.equipModelNum = :equipModelNum"),
    @NamedQuery(name = "Equipment.findByEquipSerialNum", query = "SELECT e FROM Equipment e WHERE e.equipSerialNum = :equipSerialNum"),
    @NamedQuery(name = "Equipment.findByEquipInUse", query = "SELECT e FROM Equipment e WHERE e.equipInUse = :equipInUse")})
public class Equipment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "equipID")
    private Integer equipID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "equipName")
    private String equipName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 100)
    @Column(name = "equipModelNum")
    private String equipModelNum;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 100)
    @Column(name = "equipSerialNum")
    private String equipSerialNum;
    @Basic(optional = false)
    @NotNull
    @Column(name = "equipInUse")
    private boolean equipInUse;
    @Basic(optional = false)
    @NotNull
    @Column(name = "equipType")
    private int equipType;
    @Basic(optional = true)
    @Size(min = 0, max = 15)
    @Column(name = "equipUID", unique=true)
    private String equipUID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "eCVesselID")
    private Collection<EquipmentCleaningHistory> echCollection;
    @OneToMany
    @JoinTable(
        name="JTEquipToVCP",
        joinColumns={ @JoinColumn(name="equipID", referencedColumnName="equipID")},
        inverseJoinColumns={ @JoinColumn(name="VCPID", referencedColumnName="VCPID", unique=true)}
    )
    private List<VesselCleaningProcedure> vcpCollection;

    public Equipment() {
    }

    public Equipment(Integer equipID) {
        this.equipID = equipID;
    }

    public Equipment(Integer equipID, String equipName, String equipModelNum, String equipSerialNum, boolean equipInUse, int equipType, String equipUID) {
        this.equipID = equipID;
        this.equipName = equipName;
        this.equipModelNum = equipModelNum;
        this.equipSerialNum = equipSerialNum;
        this.equipInUse = equipInUse;
        this.equipUID = equipUID;
        this.equipType = equipType;
    }

    public Integer getEquipID() {
        return equipID;
    }

    public void setEquipID(Integer equipID) {
        this.equipID = equipID;
    }

    public String getEquipName() {
        return equipName;
    }

    public void setEquipName(String equipName) {
        this.equipName = equipName;
    }

    public String getEquipModelNum() {
        return equipModelNum;
    }

    public void setEquipModelNum(String equipModelNum) {
        this.equipModelNum = equipModelNum;
    }

    public String getEquipSerialNum() {
        return equipSerialNum;
    }

    public void setEquipSerialNum(String equipSerialNum) {
        this.equipSerialNum = equipSerialNum;
    }

    public boolean getEquipInUse() {
        return equipInUse;
    }

    public void setEquipInUse(boolean equipInUse) {
        this.equipInUse = equipInUse;
    }

    public int getEquipType() {
        return equipType;
    }

    public void setEquipType(int equipType) {
        this.equipType = equipType;
    }

    public String getEquipUID() {
        return equipUID;
    }

    public void setEquipUID(String equipUID) {
        if(equipUID!=null){
            this.equipUID = equipUID;
        }
    }

    public List<VesselCleaningProcedure> getVcpCollection() {
        return vcpCollection;
    }

    public void setVcpCollection(List<VesselCleaningProcedure> vcpCollection) {
        this.vcpCollection = vcpCollection;
    }

    @XmlTransient
    public Collection<EquipmentCleaningHistory> getECHCollection() {
        return echCollection;
    }

    public void setECHCollection(Collection<EquipmentCleaningHistory> echCollection) {
        this.echCollection = echCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (equipID != null ? equipID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Equipment)) {
            return false;
        }
        Equipment other = (Equipment) object;
        if ((this.equipID == null && other.equipID != null) || (this.equipID != null && !this.equipID.equals(other.equipID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Equipment[ equipID=" + equipID + " ]";
    }
    
}
